
package com.babble.blog.config;

import com.babble.blog.rabbitCustomer.MyAckReceiver;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class MessageListenerConfig {
    @Resource
    private CachingConnectionFactory cachingConnectionFactory;
    @Resource
    private MyAckReceiver myAckReceiver;

    /**
     * @return
     * @Date 2020/12/30 16:21
     * @Author jiangheng
     * @Description
     **/
    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer() {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
        //设置最小并发的消费者数量
        container.setConcurrentConsumers(1);
        //设置最大并发的消费者数量
        container.setMaxConcurrentConsumers(20);
        //限流，单位时间内消费多少条记录
        container.setPrefetchCount(10);
        //设置rabbit 确认消息的模式，默认是自动确认
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        //设置一个队列
        //container.setQueueNames("testDirectQueue");
        //监听队列名称
        container.setQueueNames("blogsave");
        //设置消息监听类
        container.setMessageListener(myAckReceiver);
        return container;
    }
}

